package com.mushuilingfeng.spring.common;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author 沐水淋风
 * @date 2024/9/18
 */
@AllArgsConstructor
@Data
public class BaseResult<T> {
    private int code;
    private String msg;
    private T data;
    
    public static <T> BaseResult<T> success(T data) {
        return new BaseResult<>(0, "success", data);
    }
    
    public static <T> BaseResult<T> fail(String msg) {
        return fail(-1, msg);
    }
    
    public static <T> BaseResult<T> fail(int code, String msg) {
        return fail(code, msg, null);
    }
    
    public static <T> BaseResult<T> fail(String msg, T errorData) {
        return new BaseResult<>(-1, msg, errorData);
    }
    
    public static <T> BaseResult<T> fail(int code, String msg, T errorData) {
        return new BaseResult<>(code, msg, errorData);
    }
    
}
